/*
 * File     : FunctionPointer.java
 * Created  : 13 May 2011
 *
 * Copyright © 2011 Matthew Wilson (mj. {my-surname} .uk {at} gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.dni.callback;

import com.googlecode.dni.DirectNativeInterface;
import com.googlecode.dni.library.CallingConvention;
import com.googlecode.dni.library.Library;
import com.googlecode.dni.library.Symbol;
import com.googlecode.dni.type.FreeableNativeObject;
import com.googlecode.dni.type.Pointer;


/**
 * <p>
 *  Represents a pointer to an executable function.
 * </p>
 * <p>
 *  The function may either be a Java method or a native function.  When the
 *  function is a native function. the type is simply a wrapper around a
 *  pointer, with a delegate that permits calling from Java (much like an
 *  interface annotated with {@link Library}).  In the native function case with
 *  natural calling convention, there is no special lifetime management
 *  required.
 * </p>
 * <p>
 *  When the function is a Java method, a thunk is required to call into the
 *  correct method on the correct object.
 * </p>
 * <p>
 *  Instances of this type require explicit lifetime management, since some
 *  instances may use a thunk.
 * </p>
 * <p>
 *  A native function pointer may be looked up from a library by using a
 *  {@link Symbol} method on a {@link Library} interface.
 * </p>
 * <p>
 *  There is no support for converting calling conventions of native functions,
 *  since DNI is designed as a library to call native functions from Java, not
 *  as a generic dynamic call library.
 * </p>
 * <h3>Notice</h3>
 * <p>
 *  <strong>
 *   This type is not intended for general extension by users of DNI.
 *  </strong>
 * </p>
 *
 * @param <T>
 *            the delegate type; must be an interface annotated with
 *            {@link Callback}
 *
 * @see Library
 * @see DirectNativeInterface#getFunctionPointerFactory(Class)
 *
 * @author Matthew Wilson
 */
public interface FunctionPointer< T > extends FreeableNativeObject
{

    /**
     * <p>
     *  Obtains the native pointer to the function to call.
     * </p>
     *
     * @return the pointer to the function
     */
    @Override
    Pointer pointer();

    /**
     * <p>
     *  Determines the calling convention of this function.
     * </p>
     *
     * @return the calling convention
     */
    CallingConvention getCallingConvention();

    /**
     * <p>
     *  Obtains the delegate that can be called from Java.
     * </p>
     *
     * @return the delegate
     */
    T getDelegate();

}
